<?php

class UserBaseAPI{
	public $key;  //跟用户中心(1zw)通信的key
	public $url;  //需要发送CURL时的地址，
	public $hostInfo_1zw;
	public $data; //发送的data,一般是一个数组。
	public $hostInfo;//自己域名
	public $error;//错误信息
	protected function __construct($data = ''){
		$this->key = Yii::app()->params['1zwinfo']['key'];
		$this->hostInfo_1zw = Yii::app()->params['1zwinfo']['url'];
		$this->data = $data;
		$this->hostInfo = Yii::app()->request->hostInfo;
	}
    /**
     * 通过CURL请求接口
     * @return [type] 返回打印的数据
     */
    public function sendCurl() {
        if(!$this->url){
            $this->error = '请求链接错误';
            return false;
        }
        $arrData = json_encode($this->data, true);
        $arrData = Encrypt::authcode($arrData, '', $this->key); //加密
        $arrData = array('sign' => $arrData, 'url' => $this->hostInfo);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $arrData);
        curl_setopt($ch, CURLOPT_NOBODY, 0);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }
}